# options 区域
## 需要用自定义的数学函数么？
option (USE_MYMATH
            "Use tutorial provided math implementation" ON)

# CMake 最低版本号要求
cmake_minimum_required (VERSION 3.0)

# 项目信息
project (Tutorial)

# 版本号
set (Tutorial_VERSION_MAJOR 1)
set (Tutorial_VERSION_MINOR 1)

# 配置一个头文件来传递一些CMake设置到源代码
## ${PROJECT_SOURCE_DIR}: 当前工程最上层的目录
## ${PROJECT_BINARY_DIR}: 当前工程的构建目录（本例中新建的build目录）
configure_file (
  "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
  "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  )

# 添加TutorialConfig.h的路径到头文件的搜索路径
include_directories("${PROJECT_BINARY_DIR}")

# add the MathFunctions library?
if (USE_MYMATH)
    include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
    ## 添加新的library
    add_subdirectory (MathFunctions)
    SET (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (USE_MYMATH)

# 指定生成目标
add_executable(tutorial tutorial.cc)
target_link_libraries (tutorial MathFunctions)


# install
SET(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
install (TARGETS tutorial DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h" DESTINATION include)


# test
include(CTest)

# does the application run
add_test (TutorialRuns tutorial 25)
